package com.program.facesigninsystem.service.impl;

import com.program.facesigninsystem.dao.ISignInRecordDao;
import com.program.facesigninsystem.dao.ITeacherDao;
import com.program.facesigninsystem.iteration.entity.UserEntity;
import com.program.facesigninsystem.service.ITeacherService;
import com.program.facesigninsystem.util.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

@Slf4j
@Service
public class TeacherServiceImpl implements ITeacherService {

    @Autowired
    private ITeacherDao iTeacherDao;
    private ISignInRecordDao iSignInRecordDao;

    @Override
    public List<Map<String, Object>> selectList(String name, String university, String academy) {
        return iTeacherDao.selectList(name,university, academy);
    }

    @Override
    public List<Map<String, Object>> selectList(String uid) {
        return iTeacherDao.selectList(uid);
    }

    @Override
    public Integer addNote(UserEntity user) {
        return iTeacherDao.addNote(user);
    }

    @Override
    public void exportExcel(String fileName, String lid, HttpServletRequest request, HttpServletResponse response, List<Map<String, String>> noSignIn) {
        List<Map<String,Object>> dataList;
        dataList = iSignInRecordDao.findSignIn(lid);
        if (noSignIn.size() != 0) {
            for (int i = 0; i < noSignIn.size(); i++) {
                Map<String, Object> map = new HashMap<>();
                map.put("name", noSignIn.get(i).get("name"));
                map.put("school", null);
                map.put("academy", null);
                map.put("major", null);
                map.put("class_name", null);
                map.put("signintime", null);
                dataList.add(map);
            }
        }
        List<String> titleList = Arrays.asList("教师姓名","学校","学院","专业");
        ExcelUtil.uploadExcelAboutUser(request, response, fileName, titleList, dataList);
    }
}
